const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/demo',{
    useNewUrlParser:true,
    useUnifiedTopology:true
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
  // we're connected!
  console.log("连接成功啦")
});

// 创建学生表schema
// const {Schema} =  mongoose.Schema;
/*
 obj={
     a:10
 }

 obj.a

 const a = obj.a;

 const { a } = obj;
*/ 
const stu_schema = new mongoose.Schema({
    name:{
        type:String,
        required:true
    },
    age:{
        type:Number,
        required:true
    },
    aa:String,
    gender:{
        type:Number,
        default:0
    }
});
// 创建model
const stuModel = mongoose.model("student",stu_schema);
/* stuModel.insertMany([
   {
     name:1212,
     age:12,
     aa:232323,
     gender:"dwdwrft4rf"
   }
],(err)=>{
    console.log(err);
}); */

/* stuModel.find({},(err,data)=>{
    console.log(err);
    console.log(data);
}); */
stuModel.find({}).then(res=>{
    console.log(res);
}).catch(err=>{
    console.log(err)
})